import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';



class LoginPage extends StatefulWidget {
  const LoginPage({super.key});

  @override
  State<LoginPage> createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {



  @override
  Widget build(BuildContext context) {
    final arg = ModalRoute.of(context)?.settings.arguments;
    print(arg);
    return const Login();
  }
}




class Login extends StatefulWidget {
  const Login({super.key});

  @override
  State<Login> createState() => _LoginState();
}

class _LoginState extends State<Login> {

  FocusNode focusNode1 = FocusNode();
  FocusNode focusNode2 = FocusNode();
  FocusScopeNode? focusScopeNode;
  GlobalKey globalKey = GlobalKey<FormState>();


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:Center(
        child: ClipRRect(
          borderRadius: BorderRadius.circular(24),
          child: Container(
            width: 380,
            height: 320,
            padding: const EdgeInsets.all(12),
            color: Theme.of(context).colorScheme.inversePrimary,
            child:  Center(
              child: Form(
                key: globalKey,
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text("登录",style:Theme.of(context).textTheme.titleLarge) ,
                    const SizedBox(height: 12,),
                     TextFormField(
                      focusNode: focusNode1,
                      decoration: const InputDecoration(
                        label: Text("账号"),
                        prefixIcon: Icon(Icons.account_circle_rounded),
                      ),
                       validator: (v){
                        return v!.trim().isNotEmpty ? null : "用户名不能为空";
                       },
                    ),
                    const  SizedBox(height: 12,),
                      TextFormField(
                      focusNode: focusNode2,
                      decoration:const InputDecoration(
                          label: Text("密码"),
                          prefixIcon: Icon(Icons.verified_user),
                      ),
                      obscureText: true,
                        validator: (v){
                        return v!.length > 6 ? null : "密码不能少于6位";
                        },
                    ),
                    const  SizedBox(height: 12,),

                    Row(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      mainAxisAlignment: MainAxisAlignment.end,
                      children: [
                      
                        ElevatedButton(onPressed: (){
                          bool isValidate = (globalKey.currentState as FormState).validate();
                          if(isValidate){

                          }
                          // if((globalKey.currentState as FormState).validate()){
                          //
                          // }
                        }, child: const Row(

                           children: [
                             Text("登录"),
                             SizedBox(width: 12,),
                             SizedBox(height: 10,width: 10,child: CircularProgressIndicator(


                             ))]

                        )),
                         const SizedBox(width: 12),
                        ElevatedButton(onPressed: (){}, child: const Text("注册")),
                        const SizedBox(width: 12,),
                        ElevatedButton(onPressed: (){
                          (globalKey.currentState as FormState).reset();
                        }, child: const Text("重置")),

                      ],
                    )
                  ],
                ),
              ),
            ),
          ),
        ),
      )
    );
  }
}


class Register extends StatefulWidget {
  const Register({super.key});

  @override
  State<Register> createState() => _RegisterState();
}

class _RegisterState extends State<Register> {
  @override
  Widget build(BuildContext context) {
    return const Placeholder(child: Text("注册组件"),);
  }
}
